package org.lanqiao.wxq.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.lanqiao.bean.Position;
import org.lanqiao.tools.BaseDao;
import org.lanqiao.wxq.dao.PositionDao;

public class PositionDaoImpl extends BaseDao implements PositionDao {

	@Override
//	发布职位
	public Integer insertPosition(Position info) {

		String sql = "INSERT INTO `LaGou`.`position`( `casThreeId`, `positionName`, `department`, "
				+ "`jobNature`, `salaryMin`, `salaryMax`, `city`, `experience`, `education`, `attraction`,"
				+ " `describe`, `address`, `companyId`, `email`, `stateId`, `date`) "
				+ "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 3, NOW());";
		try {
			return query.update(sql, info.getCasThreeId(), info.getpositionName(), info.getDepartment(),
					info.getjobNature(), info.getSalaryMin(), info.getSalaryMax(), info.getCity(), info.getExperience(),
					info.getEducation(), info.getAttraction(), info.getDescribe(), info.getAddress(),
					info.getCompanyId(), info.getEmail());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
//	搜索职位、出错？用MapListHandler
	public List<Position> selectPositionByName(String positionName) {
		String sql = "select * from position where positionName like '%?%'"; // ？在这里没用
		try {
			return query.query(sql, new BeanListHandler<Position>(Position.class), positionName);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
//	修改职位信息
	public Integer updataPositionById(Position info) {

		String sql = "update position set casThreeId=?,positionName=?,department=?,jobNature=?,salaryMin=?, salaryMax=?,city=?,experience=?,education=?,attraction=?,describe=?,address=?,companyId=?,email=?,stateId=? where id=?";
		try {
			return query.update(sql, info.getCasThreeId(), info.getpositionName(), info.getDepartment(),
					info.getjobNature(), info.getSalaryMin(), info.getSalaryMax(), info.getCity(), info.getExperience(),
					info.getEducation(), info.getAttraction(), info.getDescribe(), info.getAddress(),
					info.getCompanyId(), info.getEmail(), info.getStateId(), info.getId());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
//	用户据状态(3有效、4下线)查询
	public List<Position> selectPositionByStateId(Integer stateId) {

		try {
			return query.query("select * from position where stateId=?", new BeanListHandler<Position>(Position.class),
					stateId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
//  后台管理员(状态5删除)
	public Integer deletePositionById(Integer id) {

		try {
			return query.update("delete * from position where id=?", new BeanHandler<Position>(Position.class), id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
